from tabnanny import verbose
from django.db import models
# from django.contrib.auth.models import AbstractUser
# class User(AbstractUser):
#     is_staff = models.BooleanField(
#         default=True,
#     )

body="""
<table class="table">
  <caption>{{ htmlName }}</caption>
  <thead>
    <tr>
      <th>id</th>
      <th>主机</th>
    </tr>
  </thead>
  <tbody>
    <tr>
    {% for d in data %}
      <td> {{ d.id }}</td>
           <td> {{ d.host }}</td>

      {% endfor %}
    </tr>
   
  </tbody>
</table>
"""

# Create your models here.
reportData="""
[
  {
    'id' : '1',
    'host' : '127.0.0.1'
  }
]
"""
class Pipeline(models.Model):
      id = models.AutoField(primary_key=True)
      name = models.CharField(verbose_name='pipeline别名', max_length=64,default="打包")

      pipeline = models.CharField(verbose_name='pipeline名字', max_length=64,default="")
      def __str__(self):
            return self.name
      class Meta:
            verbose_name="devops"
            verbose_name_plural = verbose_name

class HtmlConfig(models.Model):
      id = models.AutoField(primary_key=True)
      htmlName = models.CharField(verbose_name='页面名字', max_length=64,default="腾讯云信息")
      htmlBody = models.TextField(verbose_name='显示内容',default=body)
      reportData = models.TextField(verbose_name='上报数据',default=reportData)

      def __str__(self):
        return self.htmlName
      class Meta:
            verbose_name="其他页面"
            verbose_name_plural = verbose_name

class Config(models.Model):
      id = models.AutoField(primary_key=True)
      name = models.CharField(verbose_name='名字', max_length=64)
      config = models.TextField(verbose_name='配置')
      def __str__(self):
            return self.name
      class Meta:
            verbose_name="配置"
            verbose_name_plural = verbose_name

class Template(models.Model):
      id = models.AutoField(primary_key=True)
      name = models.CharField(verbose_name='模板名', max_length=64)
      config = models.CharField(verbose_name='配置', max_length=64)
      config = models.ManyToManyField(Config,blank=True,verbose_name='配置',related_name='pk_config')
      pipeline = models.ManyToManyField(Pipeline,blank=True,verbose_name='pipeline',related_name='pk_pipeline')

      def __str__(self):
        return self.name
      class Meta:
            verbose_name="模板"
            verbose_name_plural = verbose_name

c="""
git : http://git.xxx.club/service/xx.git
decsribe : 测试项目
"""
class Project(models.Model):
      id = models.AutoField(primary_key=True)
      name = models.CharField(verbose_name='项目名字', max_length=64)
      config = models.TextField(verbose_name='项目配置',default=c)
      temp = models.ForeignKey(Template,  on_delete=models.CASCADE,verbose_name='模板选择',related_name='pk_temp',null=True)

      def __str__(self):
        return self.name
      class Meta:
            verbose_name="项目"            
            verbose_name_plural = verbose_name
